<div class=" admin-content">
<div class="admin-biaogelist">
	
    <div class="listbiaoti am-cf">
      <ul class="am-icon-flag on"> 栏目名称</ul>
      
      <dl class="am-icon-home" style="float: right;"> 当前位置： <a href="{:U('Index/Index')}">首页</a> > 文章管理</dl>
      
      <dl>
        <a href="{:U('add')}" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus"> 添加文章</a>
      </dl>
    </div>
	<div class="am-btn-toolbars am-btn-toolbar am-kg am-cf">
  <form action="{:U('index')}" method="get">
  <ul>
    <li>
      <div class="am-btn-group am-btn-group-xs">
        <select name="cate_id" data-am-selected="{btnWidth: 150, btnSize: 'sm', btnStyle: 'default'}">
          <option value="0">文章分类</option>
          <volist name="tree" id="vo">
          <option value="{$vo.id}" <if condition="$cate_id eq $vo['id']">selected</if> ><if condition="$vo['level'] neq 0">└</if>{:str_repeat('─',$vo['level'])}{$vo.name}</option>
          </volist>
        </select>
      </div>
    </li>

    <li><input type="text" name="name" value="{$name}" class="am-form-field am-input-sm am-input-xm" placeholder="输入文章标题" /></li>
    <li><button class="am-btn am-radius am-btn-xs am-btn-success" style="margin-top: -1px;">搜索</button></li>
  </ul>
  </form>
</div>


    <form class="am-form am-g" id="cont_form">
          <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
            <thead>
              <tr class="am-success">
                <th class="table-check"></th>
                <th class="table-id">ID</th>
                <th class="table-id">排序</th>
                <th class="table-title">标题</th>
                <th>内容</th>
                <th width="150px">文章类别</th>
                <th width="100px">推荐 <i class="am-icon-check am-text-warning"></i> <i class="am-icon-close am-text-primary"></i></th>
                <th width="70px">点击量</th>
                <th class="table-type">发布日期</th>
                
                <th width="163px" class="table-set">操作</th>
              </tr>
            </thead>
            <tbody>
            <volist name="data" id="vo">
              <tr>
                <td><input type="checkbox" name="id[]" value="{$vo.id}" /></td>
                <td>{$vo.id}</td>
                <td>{$vo.sort}</td>
                <td>{:zn_substr($vo['name'],0,15)}</td>
                <td>{:zn_substr($vo['content'],0,20)}</td>
                <td><php>echo M('Cate')->where(array('id'=>$vo['cate_id']))->getField('name');</php></td>
                <td class="am-hide-sm-only">
                <if condition="$vo['recom'] eq 1"><i class="am-icon-check am-text-warning"></i>
                <else /><i class="am-icon-close am-text-primary"></i>
                </if>
                </td>
                <td>{$vo.pv}</td>
                <td class="am-hide-sm-only">{:date('Y-m-d H:m:s',$vo['publish_time'])}</td>
                <td><div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                      <a href="{:U('edit',array('id'=>$vo['id']))}" class="am-btn am-btn-default am-btn-xs am-text-secondary am-round">编辑</a>
                      <button type="button" onclick="del({$vo.id})" class="am-btn am-btn-default am-btn-xs am-text-danger am-round">删除</button>
                    </div>
                  </div></td>
              </tr>
              </volist>
              
            </tbody>
          </table>
          <div class="am-btn-group am-btn-group-xs" style="z-index:99;">
              <input type="checkbox" id="checkall"> 全选
            </div>
          
                 <div class="am-btn-group am-btn-group-xs" style="z-index:99;">
              <button id="alldel" type="button" class="am-btn am-btn-red">批量删除</button>
            </div>
            {$show}
        </form>
<script type="text/javascript">
  //单个删除
  function del(id){
    if(!confirm('确定要删除吗？')){
      return false;
    }
    $.ajax({
      url : "{:U('del')}",
      data : {'id':id},
      type : 'post',
      dataType : 'json',
      success : function(res){
        if(res.status == 'OK'){
          alert(res.msg);
          location = "__SELF__";
        }
        else if(res.status == 'NO'){
          alert(res.msg);
        }
      }
    });
  }

  //批量删除
  $('#alldel').on('click',function(){
    var Checkbox = false;
    $("input[name='id[]']").each(function() {
      if(this.checked == true) {
        Checkbox = true;
      }
    });
    if(!Checkbox){
      alert('请选择要删除的内容');
      return false;
    }
    if(!confirm('确定要删除选中内容吗？')){
      return false;
    }
    var data = $("#cont_form").serialize()
    $.ajax({
      url : "{:U('alldel')}",
      data : data,
      type : 'post',
      dataType : 'json',
      success : function(res){
        if(res.status == 'OK'){
          alert(res.msg);
          location = "__SELF__";
        }
        else if(res.status == 'NO'){
          alert(res.msg);
        }
      }
    });
  })
  
  //全选
  $("#checkall").click(function() {
    if(this.checked){
      this.checked = true;
      $("input[name='id[]']").each(function() {
        this.checked = true;
      });
    }
    else{
      this.checked = false;
      $("input[name='id[]']").each(function() {
        this.checked = false;
      });
    }
    
  });

</script>